package com.cskaoyan.market.service.impl;

import com.cskaoyan.market.service.MemberFeedbackService;
import com.cskaoyan.market.db.domain.MarketFeedback;
import com.cskaoyan.market.db.domain.MarketFeedbackExample;
import com.cskaoyan.market.db.mapper.MarketFeedbackMapper;
import com.cskaoyan.market.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * @author TangHonghao
 * @since 2023/03/21 11:50
 */
public class MemberFeedbackServiceImpl implements MemberFeedbackService {
    @Override
    public List<MarketFeedback> selectFeedbackByUsername(String username) {
        SqlSession session = MyBatisUtil.getSession();
        MarketFeedbackMapper feedbackMapper = session.getMapper(MarketFeedbackMapper.class);
        MarketFeedbackExample marketFeedbackExample = new MarketFeedbackExample();
        marketFeedbackExample.or().andUsernameEqualTo(username);
        List<MarketFeedback> marketFeedbacks = feedbackMapper.selectByExample(marketFeedbackExample);
        session.commit();
        session.close();
        return marketFeedbacks;
    }

    @Override
    public List<MarketFeedback> selectFeedbackByFeedbackId(Integer feedbackId) {
        SqlSession session = MyBatisUtil.getSession();
        MarketFeedbackMapper feedbackMapper = session.getMapper(MarketFeedbackMapper.class);
        MarketFeedbackExample marketFeedbackExample = new MarketFeedbackExample();
        marketFeedbackExample.or().andIdEqualTo(feedbackId);
        List<MarketFeedback> marketFeedbacks = feedbackMapper.selectByExample(marketFeedbackExample);
        session.commit();
        session.close();
        return marketFeedbacks;
    }

    @Override
    public List<MarketFeedback> selectFeedbackAll() {
        SqlSession session = MyBatisUtil.getSession();
        MarketFeedbackMapper feedbackMapper = session.getMapper(MarketFeedbackMapper.class);
        MarketFeedbackExample marketFeedbackExample = new MarketFeedbackExample();
        List<MarketFeedback> marketFeedbacks = feedbackMapper.selectByExample(marketFeedbackExample);
        return marketFeedbacks;
    }
}
